﻿<?Lassoscript
// Last modified 12/14/11 by ECL, Landmann InterActive

// CHANGE NOTES
// 8/7/11
// First implementation.
// 12/14/11
// Adding Slider Settings fields

// Var('svDebug' = 'Y');

If($svDebug == 'Y');
	'<p class="debug"><strong>frm_slidergroups</strong></p>\n';
/If;

// Defining the DataType
Var('vDataType' = 'SliderGroup');

// Convert action_params
Include(($svAdminHelpersPath)+'slidergroup_params.inc');

// If Edit page, get the record
If(Response_Filepath >> $svEditRecordPage);

	// Initialize variables
	Var('IsSelected' = ' selected');

	// If Process = Y, form was submit, so update the record
	// Otherwise, it is a new edit so get the record
	If($vProcess != 'Y');

		// If error 1021, action was a successful delete, so display error and abort right away
		If($vError == '1021');
			LI_ShowError3(-ErrNum=$vError, -Option=$vOption);
			Abort;
		/If;

		// Get the record
		Var('SQLGetSliderGroups' = (StripBackticks('SELECT * FROM '+($svSliderGroupsTable)+' WHERE sg_groupid = "'+($vSliderGroupID)+'" LIMIT 1')));
		Inline($IV_Sliders, -Table=$svSliderGroupsTable, -SQL=$SQLGetSliderGroups);

			If($svDebug == 'Y');
				('<p class="debug">32: Error_CurrentError = '+(Error_CurrentError)+'</p>\n');
			/If;

			// If Found_Count is wrong, the wrong User ID was passed, so dump out 2000 "No Record Found"	
			If(Found_Count == 0);
				$vError = '2000';
				LI_ShowError3(-ErrNum=$vError, -Option=$vOption);
				If($svDebug == 'Y');
					Include(($svBaseHelpersPath)+'vardumpalpha.inc');
				/If;
				Abort;
			/If;
			Var('vsg_Name' = Field('SG_Name'));
			Var('vActive' = Field('Active'));
			Var('SliderTypeID' = Field('Slider_TypeID'));
			Var('vDateModified' = Field('DateModified'));
		/Inline;

		// If there is an error, dump out error 1012 "Update Failed"
		If(Error_CurrentError != 0);
			$vError = '2000';
		/If;

// Call the Javascript to load the Configuration table
// This script must be located here because before this point we don't have the correct variables defined
?>
	<!-- 1 -->
	<script type="text/javascript">
		$(document).ready( function() {
			// This fires on the initial load only so we have some data on first pageload
			$('#SliderConfigs').load('/app/modules/admin/helpers/lookup_sliderconfigs.lasso?SliderTypeID=[$SliderTypeID]&SliderConfigID=[$vSliderGroupID]', function() {
				/* alert('1 - Load was performed'); */
				/* console.log( response ); */
			} );
		} );
	</script>
<?Lassoscript
		// Get the slider configuration
		Var('SQLGetSliderGroupConfig' = (StripBackticks('SELECT * FROM '+($svSliderConfigTable)+' WHERE SG_GroupID = "'+($vSliderGroupID)+'"')));
		Inline($IV_Sliders, -Table=$svSliderConfigTable, -SQL=$SQLGetSliderGroupConfig);

			If($svDebug == 'Y');
				('<p class="debug">69: Error_CurrentError = '+(Error_CurrentError)+'</p>\n');
			/If;

			// If Found_Count is wrong, the wrong User ID was passed, so dump out 2000 "No Record Found"	
			If(Found_Count == 0);
				$vError = '2000';
				LI_ShowError3(-ErrNum=$vError, -Option=$vOption);
				If($svDebug == 'Y');
					Include(($svBaseHelpersPath)+'vardumpalpha.inc');
				/If;
				Abort;
			/If;
			// Build the array of slider configuration settings
			Var('SliderConfigArray' = (lp_array));
			Records;
				$SliderConfigArray->(insertpair((Field('SliderConfigName')) = (Field('SliderConfigValue'))));
			/Records;

			Debug;
				('<strong>frm_slidergroup.inc</strong><br>\n');
				('90: vSliderGroupID = '+($vSliderGroupID)+'<br>\n');
				('90: SliderTypeID = '+($SliderTypeID)+'<br>\n');
				('90: SliderConfigArray = '+($SliderConfigArray)+'<br>\n');
			/Debug;

		/Inline;

	/If;

Else;
// Call the Javascript to load the Configuration table
// This script must be located here because before this point we don't have the correct variables defined
?>
	<!-- 2 -->
	<script type="text/javascript">
		$(document).ready( function() {
			// This fires on the initial load only so we have some data on first pageload
			$('#SliderConfigs').load('/app/modules/admin/helpers/lookup_sliderconfigs.lasso?SliderTypeID=[$SliderTypeID]&SliderConfigID=[$vSliderGroupID]', function() {
				/* alert('2 - Load was performed'); */
				/* console.log( response ); */
			} );
		} );
	</script>
<?Lassoscript

/If;

If(Var('vSliderGroupID') == '');
	('<h2>'+(LI_ShowIconByDataType)+'&nbsp;&nbsp;Add Slider Group</h2>\n');
Else;
	('<h2>'+(LI_ShowIconByDataType)+'&nbsp;&nbsp;Edit Slider Group</h2>\n');
/If;

// Standard Error Table
If($vError != '');
	LI_ShowError3(-ErrNum=$vError, -Option=$vOption);
/If;
?>
<form action="[$svAdminControllersPath][$svAddResponsePage]" method="post" id="SliderTypeSelect">
	<table width="500">
		<tr>
			<td width="120" class="tablehead_10_white_right">Slider Group Name[$svInputRequired]</td>
			<td width="280" bgcolor="#f0f0f0">
				<input type="text" name="sg_name" value="[$vsg_name]" size="32" maxlength="255">
			</td>
		</tr>
		<tr>
			<td width="120" class="tablehead_10_white_right">Slider Type[$svInputRequired]</td>
			<td width="280" bgcolor="#f0f0f0">
				<select name="SliderTypeID" id="SliderTypeID">
					<option value="" name="Empty">Please Select...</option>
<?Lassoscript
Var('SQLGetSliderTypes' = ('SELECT * FROM '+($svSliderTypeTable)));
Inline(-Database=$svSiteDatabase, -Table=$svSliderTypeTable, -SQL=$SQLGetSliderTypes);
	Records;
?>
					<option value="[Field('Slider_SliderTypeID')]" name="[Field('Slider_Type')]"[If((Field('Slider_SliderTypeID') == $SliderTypeIDSubmit) || (Field('Slider_SliderTypeID') == $SliderTypeID))] selected[/If]>[Field('Slider_Type')]</option>
<?Lassoscript
	/Records;
/Inline;
?>			</select>
		</td>
	</tr>
</table>
<!-- sliderconfigs -->
<?Lassoscript
// Display the table with the Slider form fields. #SliderConfigs is populated by the result of lookup_sliderconfigs.lasso
?>
<table id="SliderConfigs">
</table>
	<table width="500">
		<tr>
			<td width="120" class="tablehead_10_white_right">Active[$svInputRequired]</td>
			<td width="280" bgcolor="#f0f0f0">
				<input type="radio" name="Active" value="Y"[If(($vActive == 'Y') || ($vActive == ''))] checked[/If]> Yes&nbsp;&nbsp;
				<input type="radio" name="Active" value="N"[If($vActive == 'N')] checked[/If]> No
			</td>
		</tr>
[If((Response_Filepath >> 'setup_edit') || (Response_Filepath >> 'setup_search'))]
		<tr>
			<td width="120" class="tablehead_10_white_right">Date Modified</td>
			<td width="280" bgcolor="#f0f0f0">
				[$vDateModified]
			</td>
		</tr>
[/If]
		<tr>
			<td colspan="2" bgcolor="#666666">
				<div align="center">
<?Lassoscript
// If Edit page, add a hidden field to show check if page is submit
If(Response_Filepath >> 'editrecord');
				('\t\t\t\t<input type="hidden" name="Process" value="Y">\n');
				('\t\t\t\t<input type="hidden" name="ID" value="'+($vSliderGroupID)+'">\n');
				('\t\t\t\t<input type="hidden" name="DataType" value="SliderGroup">\n');
				('\t\t\t\t<input type="submit" name="Action" value="Update">\n');
				('\t\t\t\t<input type="submit" name="Action" value="Delete" onClick="return confirmDeleteContent()">\n');
Else;
				('\t\t\t\t<input type="submit" name="Action" value="Add">\n');
				('\t\t\t\t<input type="hidden" name="DataType" value="SliderGroup">\n');
/If; ?>			</div>
			</td>
		</tr>
	</table>
</form>
<br>
<?Lassoscript
// Assignment Slider Entry to Slider
If(Response_Filepath !>> $svAddPage);
?>&nbsp;<br>
<form action="[$svAdminControllersPath][$svAddResponsePage]" method="post">
	<table width="520">
		<tr>
			<td colspan="2" bgcolor="#666666" class="tablehead_10_white">Slider Entries</td>
		</tr>
	</table>
	<table width="520">
		<tr>
			<td width="120" bgcolor="#666666">
				&nbsp;
			</td>
			<td valign="top" bgcolor="#cccccc">
				<select name="slider_entries" multiple size="10" class="medium" style="height:180px">
<?Lassoscript
// Call the CT to build the multiple select box
LI_BuildSliderMultiSelect(-ID=$vSliderGroupID);
?>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" bgcolor="#666666">
				<div align="center">
					<input type="hidden" name="Process" value="Y">
					<input type="hidden" name="SliderGroupID" value="[$vSliderGroupID]">
					<input type="hidden" name="DataType" value="SliderGroup">
					<input type="submit" name="Action" value="Assign">
				</div>
			</td>
		</tr>
	</table>
</form>
<br>
[/If]
